package com.example.cloud.config;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import com.netflix.appinfo.EurekaInstanceConfig;

/**
 * 设置Eureka Meta信息
 * 
 * @author tongyufu
 *
 */
@Configuration
@EnableConfigurationProperties
//@ConditionalOnBean(EurekaInstanceConfig.class)
public class GrpcMetedataEurekaConfiguration {

    @Autowired
    private EurekaInstanceConfig instanceConfig;
    @Autowired
    private GRpcServerProperties serverProperties;

    /**
     * 注册Eureka服务时，将grpc端口放入Metadata中
     */
    @PostConstruct
    public void init() {
        this.instanceConfig.getMetadataMap().put("grpc", serverProperties.getPort().toString());
    }
}
